﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sustainalytics.DataLayer.ConnectionStrings;
using Sustainalytics.Entities.ConnectionStrings;
using Sustainalytics.Synchronization.Interface;
using Sustainalytics.Utils;

namespace Sustainalytics.PregenerateScreeningReports.Tests
{
    [TestClass]
    public class SyncStepIntegrationTests
    {
        private static string _clientPlatformConnectionString;

        [TestMethod]
        public void ISyncStep_Start_Test()
        {
            _clientPlatformConnectionString = "mongodb://sustadmin:G4nd4lf2014@54.171.12.91,52.19.138.58/ClientPlatform?connect=replicaset;replicaSet=gapStage";

            var clientDwConnectionString = GetConnectionString(ConnectionStringType.ClientDW);
            var clientUniversesConnectionString = GetConnectionString(ConnectionStringType.ClientUniverses);

            var connectionStrings = new Dictionary<string, string>
            {
                {"ClientDWMaster", _clientPlatformConnectionString.Replace("ClientPlatform", "ClientDWMaster")},//"mongodb://localhost:27017/ClientPlatform"},
                {"ClientPlatform", _clientPlatformConnectionString},//"mongodb://localhost:27017/ClientPlatform"},
                {"ClientUniverses", clientUniversesConnectionString.Replace("10.11.7.141", "54.171.12.91").Replace("10.0.1.11", "52.19.138.58")}, // "mongodb://localhost:27017/ClientDW_A"},
                {"ClientDW", clientDwConnectionString.Replace("10.11.7.141", "54.171.12.91").Replace("10.0.1.11", "52.19.138.58")},
                {"ScreeningDW", _clientPlatformConnectionString},
            };

            var syncContext = new SyncContext
            {
                LastSyncTime = new DateTime(2010, 1, 1),
                GAConnectionStrings = connectionStrings,
                PreviousChanges = new List<ChangedElement>(),
                Report = new ConcurrentBag<string>(),
            };

            var cron = new Cronometer();

            var syncStep = new PregenerateStandardReportsSyncStep();
            syncStep.Start(syncContext);

            cron.Mark("one");
        }

        private static string GetConnectionString(ConnectionStringType connectionStringType)
        {
            var connectionStringsManager =
                ConnectionStringsManager.GetInstance(
                    ConnectionStringsRepository.GetInstance(_clientPlatformConnectionString));

            return connectionStringsManager.GetConnectionString(connectionStringType);
        }
    }
}
